<template>
  <div class="label-page-container">
    <div class="page-list">
      <div
        class="item"
        v-for="(page, index) in pageList"
        :key="index"
        @click="activePage(page)"
      >
        <span class="circle" :style="[page.isCurrent ? active : '']"></span>
        <span class="text">{{ page.text }}</span>
        <span
          class="close el-icon-close"
          @click.stop="DEL_LABEL_PAGE(index)"
        ></span>
      </div>
    </div>
    <div class="right">
      <el-dropdown :style="{ 'background-color': theme.color }">
        <span class="el-dropdown-link">
          标签选项<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="CLOSE(1)">关闭其他</el-dropdown-item>
          <el-dropdown-item @click.native="CLOSE(0)">
            关闭所有
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'label-page',
  methods: {
    ...mapMutations('labelPage', ['DEL_LABEL_PAGE', 'ACTIVE_PAGE', 'CLOSE']),
    // 激活页面
    activePage(page) {
      this.$router.push(page.path)
      this.ACTIVE_PAGE(page)
    },
  },
  computed: {
    ...mapState('labelPage', ['pageList']),
    ...mapState('theme', ['theme']),
    // 激活样式
    active() {
      return { 'background-color': this.theme.color }
    },
  },
}
</script>

<style lang="scss">
.label-page-container {
  position: relative;
  height: 45px;
  border-top: 1px solid #eee;
  border-bottom: 1px solid #eee;
  background-color: #eee;
  .page-list {
    width: calc(100% - 160px);
    margin-top: 4px;
    padding-bottom: 6px;
    box-sizing: border-box;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    &::-webkit-scrollbar {
      height: 4px;
      background-color: rgba(0, 0, 0, 0.1);
      border-radius: 2px;
    }
    &::-webkit-scrollbar-thumb {
      height: 4px;
      border-radius: 2px;
      background-color: rgba(0, 0, 0, 0.25);
    }
  }
  .item {
    display: inline-block;
    height: 30px;
    margin-left: 15px;
    background-color: #fff;
    line-height: 30px;
    border-radius: 5px;
    font-size: 14px;
    cursor: default;
    .circle {
      display: inline-block;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background-color: #ddd;
      margin: 0 8px;
    }
    .close {
      width: 30px;
      height: 30px;
      text-align: center;
      line-height: 30px;
    }
  }
  .right {
    position: absolute;
    top: 0;
    right: 10px;
    width: 100px;
    height: 35px;
    margin-top: 5px;
    background-color: #fff;
    border-radius: 5px;
    box-shadow: 0 0 0 2px #ddd;
    text-align: center;
    cursor: pointer;
    .el-dropdown {
      width: 90px;
      height: 25px;
      margin-top: 4px;
      border-radius: 5px;
      font-size: 13px;
      text-align: center;
      line-height: 28px;
      color: #fff;
    }
  }
}
</style>
